// MainFrm.h : interface of the CMainFrame class
//
/////////////////////////////////////////////////////////////////////////////

#if !defined(AFX_MAINFRM_H__4E614EAB_75B9_4B7A_87FB_DDFFF6B86D50__INCLUDED_)
#define AFX_MAINFRM_H__4E614EAB_75B9_4B7A_87FB_DDFFF6B86D50__INCLUDED_

#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000

 
#include "MDIMenuControl.h"

class CMainFrame :  public CMDIFrameWindowImpl<CMainFrame>, 
					public CUpdateUI<CMainFrame>,
					public CMessageFilter,
					public CIdleHandler
{ 	
public:
 	DECLARE_FRAME_WND_CLASS("WTL_MAIN_WND_CLASS", IDR_MAINFRAME)
		
	CMainFrame();
	~CMainFrame();
	
	virtual BOOL PreTranslateMessage(MSG* pMsg);
	virtual BOOL OnIdle();
	
	BEGIN_UPDATE_UI_MAP(CMainFrame)  
		UPDATE_ELEMENT(ID_FILE_NEW, UPDUI_MENUPOPUP | UPDUI_TOOLBAR)
		UPDATE_ELEMENT(ID_VIEW_TOOL_BAR, UPDUI_MENUPOPUP)		 
	END_UPDATE_UI_MAP()
		
	BEGIN_MSG_MAP(CMainFrame)
		MESSAGE_HANDLER(WM_CREATE, OnCreate)	
		MESSAGE_HANDLER(WM_COMMAND, OnCommand)
		CHAIN_MSG_MAP(CUpdateUI<CMainFrame>)
		CHAIN_MSG_MAP(CMDIFrameWindowImpl<CMainFrame>)		
	END_MSG_MAP()
		 
	LRESULT OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
	LRESULT OnCommand(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& bHandled);

  
private:   
	CMDICommandBarCtrl		m_CmdBar;
	CMDIMenuControl			m_MenuControl;
	CMultiPaneStatusBarCtrl m_SBCtrl;
	
	private:
		void pvFileExit(WORD wID)
		{
			if(ID_APP_EXIT == wID)
			{
				printf("ID_APP_EXIT: ...\n"); 
				PostMessage(WM_CLOSE);
			}
		}
		void pvViewToolBar(WORD wID)
		{
			if(ID_VIEW_TOOL_BAR == wID)
			{
				printf("OnCommand: wParam= ID_VIEW_TOOL_BAR\n"); 
				static BOOL bVisible = TRUE;	// initially visible
				bVisible = !bVisible;
				CReBarCtrl rebar = m_hWndToolBar;
				int nBandIndex = rebar.IdToIndex(ATL_IDW_BAND_FIRST + 1);	// toolbar is 2nd added band
				rebar.ShowBand(nBandIndex, bVisible);
				UISetCheck(ID_VIEW_TOOL_BAR, bVisible);
				UpdateLayout();
			}
		}
		void pvMyTitle()
		{ 
			char szFilePath[256]; 
			memset(szFilePath,0,256); 
			::GetModuleFileName(NULL,szFilePath,256);
			PathRemoveFileSpec(szFilePath); 
			char szMyDir[256];
			sprintf(szMyDir,"%s\\BlWtlUI.dll",szFilePath);
			 
			
			char szV[256];
			xdGetModuleVersion(szMyDir,szV);
			
			CString strTitle;
			strTitle.Format("BlWtlUI.dll[%s]", szV);
			SetWindowText(strTitle);
		}
				void xdGetModuleVersion(IN char *szFullPath,OUT char *szV)
	{ 
		DWORD dwVerInfoSize = 0;
		DWORD dwVerHnd;
		VS_FIXEDFILEINFO * pFileInfo;
		
		//	GetModuleFileName(NULL, szFullPath, sizeof(szFullPath));
		dwVerInfoSize = GetFileVersionInfoSize(szFullPath, &dwVerHnd);
		if (dwVerInfoSize)
		{
			// If we were able to get the information, process it:
			HANDLE  hMem;
			LPVOID  lpvMem;
			unsigned int uInfoSize = 0;
			
			hMem = GlobalAlloc(GMEM_MOVEABLE, dwVerInfoSize);
			lpvMem = GlobalLock(hMem);
			GetFileVersionInfo(szFullPath, dwVerHnd, dwVerInfoSize, lpvMem);
			
			::VerQueryValue(lpvMem, (LPTSTR)_T("\\"), (void**)&pFileInfo, &uInfoSize);
			
			WORD m_nProdVersion[4];
			
			// Product version from the FILEVERSION of the version info resource 
			m_nProdVersion[0] = HIWORD(pFileInfo->dwProductVersionMS); 
			m_nProdVersion[1] = LOWORD(pFileInfo->dwProductVersionMS);
			m_nProdVersion[2] = HIWORD(pFileInfo->dwProductVersionLS);
			m_nProdVersion[3] = LOWORD(pFileInfo->dwProductVersionLS); 
			
			//*
			sprintf(szV,_T("%d.%d.%d.%d"),m_nProdVersion[0],
				m_nProdVersion[1],m_nProdVersion[2],m_nProdVersion[3]);
			//*/
			
			GlobalUnlock(hMem);
			GlobalFree(hMem);
			
			
		}
	}

	
};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_MAINFRM_H__4E614EAB_75B9_4B7A_87FB_DDFFF6B86D50__INCLUDED_)
